__author__ = "klegonidec"
__license__ = "WTFPL"

import time
import numpy as np
import matplotlib.pyplot as plt



def predicate_check(predicate, str):
	"""Print the success of a named-predicate"""
	print "\t", str

	if predicate():
		print "\t\tSUCCESS"
	else:
		print "\t\tFAIL"


def execution_time(funct,name):
	"""Return the result and the time taken by a lambda to be executed"""
	start = time.clock()
	ret = funct()
	total = time.clock() - start
	print '%s took %.2f seconds' % (name,total)
	return [ret,total]

def comparison_function_figure(funct1,funct2,nb,xLabel,yLabel,nameF1, nameF2,figureName):
	x = np.arange(0.0, nb, 1)
	f1y = np.arange(0.0, nb, 1)
	f2y = np.arange(0.0, nb, 1)
	for i in np.arange(0,nb):
		f1y[i] = funct1(i)

	for i in np.arange(0,nb):
		f2y[i] = funct2(i)

	plt.clf()
	g1 = plt.plot(x, f1y, linewidth=1.0)
	g2 = plt.plot(x, f2y, linewidth=1.0)
	plt.xlabel(xLabel)
	plt.ylabel(yLabel)
	plt.legend((g1,g2),(nameF1,nameF2))
	plt.savefig(figureName+".png")
	plt.show()
